<template>
	<div class="addressadd">
		<van-nav-bar title="新增地址" left-arrow @click-left="onClickLeft" />
		<div class="addressform" v-model="address">
			<van-form @submit="onSubmit">
			  <van-field
			    v-model="address.receiver_name"
			    name="收货人姓名"
			    label="收货人姓名"
			    placeholder="收货人姓名"
			    :rules="[{ required: true, message: '请填写收货人姓名' }]"
			  />
			  <van-field
			    v-model="address.receiver_telephone"
			    name="手机号"
			    label="手机号"
			    placeholder="手机号"
			    :rules="[{ required: true, message: '请填写手机号' }]"
			  />
			  <van-field
			    v-model="address.receiver_address"
			    name="详细地址"
			    label="详细地址"
			    placeholder="详细地址"
			    :rules="[{ required: true, message: '请填写详细地址' }]"
			  />
			  <van-field name="defaultadd" label="默认地址" >
			    <template #input>
			      <van-switch v-model="defaultadd" size="20" />
			    </template>
			  </van-field>
			  <van-field name="radio" label="标签" >
			    <template #input>
			      <van-radio-group v-model="radio" direction="horizontal">
			        <van-radio name="家">家 </van-radio>
			        <van-radio name="学校">学校</van-radio>
					<van-radio name="公司">公司</van-radio>
			      </van-radio-group>
			    </template>
			  </van-field>
			  <div style="margin: 16px;">
			    <van-button round block type="info" native-type="submit">
			      添加地址
			    </van-button>
			  </div>
			</van-form>
		</div>
	</div>
</template>

<script>
	import {
		Toast
	} from 'vant';
	import { Notify } from 'vant';
	export default{
		name:"AddressAdd",
		data() {
			return {
				radio:'',//标签
				defaultadd:false,//默认地址
				address: {
					user_id:2,
					receiver_name: '',
					receiver_label: '',
					receiver_address: '',
					receiver_telephone: '',
					defult_flag:1,
					is_delete:1,
				},
			};
		},
		created() {
			this.axios.get(`http://localhost:8080///user/getlogin`).then(res => {
				//console.log(res.data.loginUser.user_id);
				this.address.user_id = res.data.loginUser.user_id;
			});
			//console.log(this.address);
			
		},
		methods: {
			onSubmit(){
				this.address.receiver_label=this.radio;
				if(this.defaultadd==false){
					this.address.defult_flag=0;
				}else{
					this.address.defult_flag=1;
				}
				console.log(this.address);
				this.axios.post(`http://localhost:8080//useraddress/addaddress`,this.address).then(res => {
					console.log(res.data)
					Notify({ type: 'success', message: '添加成功' });
					this.$router.replace('/personal/address');
				})
				
			},
			onClickLeft() {
				this.$router.replace('/personal/address');
			},
			
		
		},
	}
</script>

<style lang="less">
</style>
